    open GdkKeysyms
    open StdLabels
    open Gobject.Data
    open GtkTree

    let debug = new Debug.debug
    let _filePath = ref "" 
    let _acc = ref 1
    let _nbTab = ref 0
    let _fileOpened = ref false
    let _inShell = ref false
    let activatedRows = ref []

    let _ = GMain.init () (* initialisation du main *)

    (* SHORTCUT *)
    let _sc_open = "Ctrl+O"
    let _sc_save = "Ctrl+S"
    let _sc_openTab = "Ctrl+T"
    let _sc_closeTab = "Ctrl+W"
    let _sc_quit = "Ctrl+Q"
    let _sc_compil = "F5"
    let _sc_reload = "F6"
    let _sc_color_info = "F7"

    (* Integrated Shell *)
    let (readme, writeme) = Unix.open_process "/bin/bash"
    let read = 
        let readdesc = Unix.descr_of_in_channel readme in
        Unix.set_nonblock readdesc;
        readdesc

    (*** Fenêtre principale ***)
    let mainWindow = GWindow.window
      ~width:800
      ~height:600
      ~position:`CENTER
      ~resizable:true
      ~title:"Aurora-reload" ()

      
    (*** Menu du haut ***)
    let vboxMenu =
      GPack.vbox
        ~spacing:4
        ~border_width:4
        ~packing:mainWindow#add ()
        
    let upMenu = GMenu.menu_bar 
      ~packing:vboxMenu#pack ()
      
    (*** Barre d'outil ***)
    let toolBar = GButton.toolbar
      ~orientation:`HORIZONTAL
      ~style:`BOTH
      ~packing:vboxMenu#pack ()
      
    (*** Structure des boxs ***)

    (*** Structure des boxs ***)

    let panedCodeTree_DebugShell = GPack.paned 
        `VERTICAL 
        ~border_width:4 
        ~packing:vboxMenu#add ()

    let panedCodeTree = GPack.paned 
        `HORIZONTAL 
        ~border_width:4 ()

    let hboxCode =
       GPack.hbox 
       ~spacing:4
       ~border_width:4()

    let hboxTree =
       GPack.hbox 
       ~spacing:4
       ~border_width:4 ()

    let _ = panedCodeTree#add1 hboxCode#coerce;
        panedCodeTree#add2 hboxTree#coerce;
        panedCodeTree#set_position 800

    let panedDebugShell = GPack.paned 
        `HORIZONTAL 
        ~border_width:4 ()

    let hboxDebug =
       GPack.hbox 
       ~spacing:4
       ~border_width:4 ()

    let hboxShell =
       GPack.hbox 
       ~spacing:4
       ~border_width:4 ()

    let _ = panedDebugShell#add1 hboxDebug#coerce;
        panedDebugShell#add2 hboxShell#coerce;
            panedDebugShell#set_position 700


    let _ = panedCodeTree_DebugShell#add1 panedCodeTree#coerce;
        panedCodeTree_DebugShell#add2 panedDebugShell#coerce;
        panedCodeTree_DebugShell#set_position 400


    (****** Ajout des NoteBook *******)
    let source_view = new Source_view.source_view 

    (*** Code principal ***)

    let abrLex = new Arbre_lexical.abrLex

    let keywordsarbre = abrLex#construit " and as assert begin class constraint do done downto else end exception external false for fun function functor if in
    include inherit initializer lazy let match method module mutable new object of
    open or private rec sig struct then to true try type val virtual when while
    with"

    let noteBookCode = new Notebook.notebook hboxCode 700 300 "Welcome"
    let _ = noteBookCode#initNoteBook

    let textCode = source_view#newTextView ~edit:true ~advance:false noteBookCode#getScroll       	 
    let _ = textCode#set_wrap_mode `CHAR; 
        source_view#endInit
        

    (*** Tree view ***)
    let noteBookTree = new Notebook.notebook hboxTree 0 0 "TreeView"
    let _ = noteBookTree#initNoteBook

    let tree_view = new Tree_view.tree_view noteBookTree#getScroll
     
    let tree = tree_view#do_tree_store

    (*** Debogueur & Info ***)
    let noteBookDebug = new Notebook.notebook hboxDebug 0 0 "Debug"
    let _ = noteBookDebug#initNoteBook

    let textDebug = source_view#newTextView ~edit:false ~advance:false noteBookDebug#getScroll       	 
    let textInfo = source_view#newTextView ~edit:false ~advance:false (noteBookDebug#createNewOnglet "Info") 
    let _ = noteBookDebug#goto_page 0


    (*** Shell ***)
    let vboxShell =
       GPack.vbox 
       ~spacing:4
       ~border_width:4
       ~packing:hboxShell#add ()

    let noteBookShell = new Notebook.notebook vboxShell 0 0 "Shell"
    let _ = noteBookShell#initNoteBook

    let textShell = source_view#newTextView ~edit:true ~advance:false noteBookShell#getScroll       	 

    let hboxShellButtons =
       GPack.hbox
       ~height:40
       ~spacing:4
       ~border_width:4
       ~packing:vboxShell#pack ()

    let editShell = GEdit.entry
        ~text:""
        ~packing:hboxShellButtons#add ()

    let _ = 
        let button = GButton.button
        ~label:"Send"
        ~packing:hboxShellButtons#pack () in 
        ignore (button#connect#clicked 
            (fun () -> Compil.send_shell editShell#text textShell read writeme; editShell#set_text ""))

    (*** fonctions utile a la creation de widget  ***)
    let fileButton label stock2 action =
      let button = GButton.button
        ~label:label
        ~packing:toolBar#add () in 
        ignore (GMisc.image ~stock:stock2 ~packing:button#set_image ());
        ignore (button#connect#clicked action);
        button
      

    (*** Popup pour save & load ***)  
    exception IsNone
      
    let strOp = function
      | Some x -> x
      | _ -> raise IsNone
      
    let codeFilter = GFile.filter
      ~name:"Code File"
      ~patterns:["*.ml"; "*.c"]()  


     let openBox str action stock id =
      let currentTextCode = (List.nth !Function._listText noteBookCode#current_page) in
        if((str = "save") && Function.fileExistInTextCode currentTextCode) then
             Function.saveText "dejaexistant" currentTextCode
        else
            begin
                let dlg = GWindow.file_chooser_dialog
                ~action:action
                ~parent:mainWindow
                ~position:`CENTER_ON_PARENT
                ~title:(match str with |"save" ->"Save file"
                                       |"saveas" -> "Save file as"
                                       |"load" -> "Load file"
                                       |_ -> "")
                ~destroy_with_parent:true () in
                dlg#set_filter codeFilter;
                dlg#add_button_stock `CANCEL `CANCEL;
                dlg#add_select_button_stock id stock;
                if dlg#run() = stock 
                then 
                 begin
                 if str = "load" then
                    begin
                 (_filePath := (strOp(dlg#filename)));
                 Function.loadText !_filePath source_view noteBookCode textCode; 
                 _fileOpened := true
                    end
                 else
                    (_filePath := (strOp(dlg#filename)));
                    Function.saveText !_filePath currentTextCode;
                    _fileOpened := true
                 end;
                 dlg#misc#hide ()
            end

    let startDialog dlg = fun () -> dlg#run (); dlg#misc#hide ()  

    (*** Fonctions -> Onglet dynamique ***)

    let createNewOnglet str = 
     source_view#newTextView ~edit:true ~advance:true (noteBookCode#createNewOnglet str)

    let removeCurrentTab _ =
        Function._listText := Notebook.listRemove !Function._listText noteBookCode#current_page;
        noteBookCode#removeCurrentTab

    (* du code deguelasse pour rentre mes onglet un peu dynamique :D *)
    let popupRightClick edit =
      let menu = GMenu.menu () in
      let menuItem = GMenu.menu_item ~label:("Add new tab `"^_sc_openTab)
      ~packing: menu#append () in
      let _ =  menuItem#connect#activate 
      ~callback:(fun _ -> ignore(createNewOnglet "Tab")) in
      let menuItem = GMenu.menu_item ~label:("Remove current tab `"^_sc_closeTab) 
      ~packing: menu#append () in
      let _ = menuItem#connect#activate
            ~callback:removeCurrentTab in 
          noteBookCode#event#connect#button_press ~callback:(fun event -> let () =
                if ((GdkEvent.Button.button event) = 3) 
                then (GtkMenu.Menu.popup
                        ~button:3
                        ~time:(GdkEvent.get_time event) (menu#as_menu))
                in false)
        (* fin du code degue *)

    let popupCode = popupRightClick true
     
    (*** Ouverture de fichier via le TreeView ***)

    let doubleClicked (view:GTree.view) =
        let model = tree_view#get_model in
         fun path column -> let selectionIter = model#get_iter path in  
        (* List.iter (model#set ~row:(model#append ()) ~column) !activatedRows;*)
             activatedRows := selectionIter::!activatedRows;
         if (model#iter_is_valid selectionIter)  
         then
             begin
                let filename = model#get 
                ~row:selectionIter
                ~column:tree_view#get_colName in
                if(not(Sys.is_directory filename)) 
                then (let _= createNewOnglet "Tab" in
                Function.loadText (tree_view#getFullPath filename) source_view
                noteBookCode textCode)
                else (tree_view#createNewDir filename (tree_view#getFullPath filename))
             end

    let _ = tree#connect#after#row_activated ~callback:(doubleClicked tree)


    (*** Fonctions -> Compilation & SVN ***)

    let compiler path =
        let currentDir = Function.cutDirPath !_filePath in
        textDebug#buffer#set_text "";
        let _ = Compil.read_process_args "make" [| "make"; "-C"; currentDir|]
        textDebug noteBookCode
        in
        textInfo#buffer#set_text "Build in progress...";
        textInfo#buffer#set_text ((textInfo#buffer#get_text ())^"\n"^"Build finished");
        if (Compil.parse_compilation_error (textDebug#buffer#get_text ())) then
          Compil.parse_compilation_line (textDebug#buffer#get_text ()) noteBookCode

    let reload _ = debug#reload "./aurora"

    let svn action =
      let currentDir = Function.cutSvnPath !_filePath in
      match action with
        | "update" -> 
            textInfo#buffer#set_text 
              ((textInfo#buffer#get_text ())^"SVN update :\n");
            let _ = debug#read_process_args
                "svn" [|"svn"; "update"; currentDir|] textInfo in
            print_endline currentDir
        | "commit" -> begin
            match GToolbox.input_string ~title:"SVN commit" 
                  ~text:"none" "Commit message" 
            with 
            | Some x -> begin 
              textInfo#buffer#set_text 
                ((textInfo#buffer#get_text ())^"SVN commit :\n");
              let _ = debug#read_process_args
                "svn" [|"svn"; "commit"; "-m"; x|] textInfo in
              print_endline currentDir
              end
            | None -> ()
            end
        | _ -> ()

    let table_tag = GText.tag_table ()
    let buffermod = GText.buffer ~tag_table:table_tag ()

    let colorInfo _ = 
      textInfo#set_buffer buffermod;
      let debut = buffermod#start_iter and fin = buffermod#end_iter in
      let tag = GText.tag () in
        tag#set_property (`FOREGROUND "green");
        table_tag#add (tag#as_tag);
        buffermod#apply_tag tag ~start:debut ~stop:fin
     
    (*** about ***)
    let aboutButton _ =
      let dialog = GWindow.about_dialog
        ~authors:
        ["EpiStudio: \n
    Theo \"DarK_Phe0niX\" Sellem\n<theo.sellem@epita.fr>\n
    Quentin \"Le Gay\" Ribière\n<quentin.ribiere@epita.fr>\n
    Johann \"TheJohKill\" Aurieres\n<johann.aurieres@epita.fr>\n
    Matthieu \"jerska(scouille)\" Dumont\n<matthieu.dumont@epita.fr>"]
        ~copyright:"Aurora © 2012 By EpiStudio"
        ~license:"LGPLv3"
        ~version:"v0.1" 
        ~website:"http://www.aurora.com"
        ~position:`CENTER_ON_PARENT
        ~parent:mainWindow
        ~destroy_with_parent:true () in
        dialog#set_name "Aurora";
        ignore(dialog#run ());
        dialog#misc#hide ()
          

    (*** quit ***)
    let quit _ = 
        if(!_fileOpened) then
        begin
      Settings.writeSettings ();
      let dlg = GWindow.message_dialog
        ~message:"<b><big> Are you sure you want to quit ?</big>\n\n\
          Care :\nEvery changes would be loose.</b>\n"
        ~parent:mainWindow
        ~destroy_with_parent:true
        ~use_markup:true
        ~message_type:`QUESTION
        ~position:`CENTER_ON_PARENT
        ~buttons:GWindow.Buttons.yes_no () in
        let res = dlg#run () = `YES in
        if (res) then
            begin
                output_string writeme "exit\n";
                flush writeme;
                ignore(Unix.close_process (readme,writeme));
                GMain.quit ();
                dlg#destroy (); 
                not(res)
            end
            else
                res
        end
        else
            begin
        Settings.writeSettings ();
                output_string writeme "exit\n";
                flush writeme;
                ignore(Unix.close_process (readme,writeme));
                GMain.quit ();
                true
            end 

    let toggleInShell selected =
      if selected
      then _inShell := true
      else _inShell := false

    (*** Search & Replace ***)
    let ask_for_file () =
      SearchReplace.addSearchReplace noteBookCode

    (** Send command to minishell **)
    let ask_minishell () = 
        let text = GToolbox.input_string ~title:"Shell"
          ~ok:"Ok" ~cancel:"Annuler" "Command ?" in
        match text with
        | None -> Compil.send_shell "" textShell read writeme
        | Some text -> Compil.send_shell text textShell read writeme

    (*** New Project ***)
    let new_project_fun () = 
        let name = GToolbox.input_string ~title:"Project name"
          ~ok:"Ok" ~cancel:"Annuler" "Project name ?" in
        match name with
          | None -> ()
          | Some text -> Project.project_create_ocaml text

    external fact : unit -> int = "f42_c"

    let print42 () = GToolbox.message_box 
        ~title:"Did you know the truth ?" 
        ~ok:"Quitter"
        ("The answer to life the universe and everything is :\n\n\t"^string_of_int(fact ()))

    let save _ = openBox "save" `SAVE `SAVE `SAVE
    let saveas _ = openBox "saveas" `SAVE `SAVE `SAVE
    let load _ = openBox "load" `OPEN `OPEN `OPEN
    
    let getCurrentNameFileWithoutExtension _ =
      let currentTextCode = (List.nth !Function._listText noteBookCode#current_page)in
	let path = Function.getPath currentTextCode in
	Function.deleteExtension path
   
 let genMakefile _ = GestionModule.generateMakefile (getCurrentNameFileWithoutExtension ())
	
let graphEntries = [
  `I ("Print Graph of the Project", fun () -> GestionModule.printGraph (getCurrentNameFileWithoutExtension ()) );
  `I ("Depth First Search", fun () -> GestionModule.parcProf (getCurrentNameFileWithoutExtension ()) );
  `I ("Breadth First Search", fun () -> GestionModule.parcLarg (getCurrentNameFileWithoutExtension ()));
]
    (*** configuration de menu en haut ***)
    let fileEntries ()=
      [
        `I ("Open `"^_sc_open, load); 
        `I ("Save `"^_sc_save, save);
        `I ("Save as", saveas);
        `S;
        `I ("New tab `"^_sc_openTab, fun _ -> ignore(createNewOnglet "Tab"));
        `I ("New dir", fun _-> tree_view#createNewDir "CurrentDir" ".");
        `I ("New project", fun _ -> new_project_fun ());
        `I ("Generate Makefile from current tab", genMakefile);
	`M ("Graph Option", graphEntries);
    `I ("Close current tab `"^_sc_closeTab, removeCurrentTab);
    `S;
    `I ("Quit `"^_sc_quit, fun _-> ignore(quit()); ());
  ]
    
let editEntries ()= 
  [
    `I ("Send to Interpreter", 
        (fun () -> Compil.send_shell 
                        ("ocaml "^(!_filePath))
                         textShell read writeme));
    `I ("Build `"^_sc_compil,compiler);
    `I ("Color Info `"^_sc_color_info, colorInfo);
    `S;
    `I ("Refacto C ",(fun _ -> let current = noteBookCode#current_page in
let currentTextCode = (List.nth !Function._listText current) in currentTextCode#buffer#set_text (Facto.refacto_c (currentTextCode#buffer#get_text()))));
    `I ("Refacto CamL ",(fun _ -> let current = noteBookCode#current_page in
let currentTextCode = (List.nth !Function._listText current) in currentTextCode#buffer#set_text (Facto.refacto_c (Facto.refacto_caml (currentTextCode#buffer#get_text())))));
    `I ("Search", fun _ -> ask_for_file ());
    `I ("Settings", Interface_option.addDialogOption);
  ]

let svnEntries = [
  `I ("Add", (fun () -> Depots.svn (Depots.ask ()) "" "add" !_inShell textInfo textShell read writeme));
  `I ("Checkout", (fun () -> Depots.svn (Depots.ask ()) "" "checkout" !_inShell textInfo textShell read writeme));
  `I ("Checkout-redo", (fun() -> Depots.svn (Depots.ask ()) (Depots.ask ()) "checkout-redo" !_inShell textInfo textShell read writeme));
  `I ("Cleanup", (fun () -> Depots.svn "" "" "cleanup" !_inShell textInfo textShell read writeme));
  `I ("Commit", (fun () -> Depots.svn (Depots.ask ()) "" "commit" !_inShell textInfo textShell read writeme));
  `I ("Commit-file", (fun () -> Depots.svn (Depots.ask ()) "" "commit-file" !_inShell textInfo textShell read writeme));
  `I ("Diff", (fun () -> Depots.svn (Depots.ask ()) "" "diff" !_inShell textInfo textShell read writeme));
  `I ("Diff-rev", (fun () -> Depots.svn (Depots.ask ()) (Depots.ask ()) "diff-rev" !_inShell textInfo textShell read writeme));
  `I ("Export", (fun () -> Depots.svn (Depots.ask ()) "" "export" !_inShell textInfo textShell read writeme));
  `I ("Export-rev", (fun () -> Depots.svn (Depots.ask ()) (Depots.ask ()) "export-rev" !_inShell textInfo textShell read writeme));
  `I ("Info", (fun () -> Depots.svn (Depots.ask ()) "" "info" !_inShell textInfo textShell read writeme));
  `I ("List", (fun () -> Depots.svn "" "" "list" !_inShell textInfo textShell read writeme));
  `I ("List-rev", (fun () -> Depots.svn (Depots.ask ()) (Depots.ask ()) "list-rev" !_inShell textInfo textShell read writeme));
  `I ("Log", (fun () -> Depots.svn (Depots.ask ()) "" "log" !_inShell textInfo textShell read writeme));
  `I ("Mkdir", (fun () -> Depots.svn (Depots.ask ()) "" "mkdir" !_inShell textInfo textShell read writeme));
  `I ("Remove", (fun () -> Depots.svn (Depots.ask ()) "" "remove" !_inShell textInfo textShell read writeme));
  `I ("Resolved", (fun () -> Depots.svn (Depots.ask ()) "" "resolved" !_inShell textInfo textShell read writeme));
  `I ("Revert", (fun () -> Depots.svn "" "" "revert" !_inShell textInfo textShell read writeme));
  `I ("Switch", (fun () -> Depots.svn (Depots.ask ()) "" "switch" !_inShell textInfo textShell read writeme));
  `I ("Status", (fun () -> Depots.svn "" "" "status" !_inShell textInfo textShell read writeme));
  `I ("Status-update", (fun () -> Depots.svn "" "" "status-update" !_inShell textInfo textShell read writeme));
  `I ("Undo", (fun () -> Depots.svn (Depots.ask ()) (Depots.ask ()) "undo" !_inShell textInfo textShell read writeme));
  `I ("Update", (fun () -> Depots.svn "" "" "update" !_inShell textInfo textShell read writeme));
]

let gitEntries = [
  `I ("Add", (fun () -> Depots.git (Depots.ask ()) "" "add" !_inShell textInfo textShell read writeme));
  `I ("Branch", (fun () -> Depots.git (Depots.ask ()) "" "branch" !_inShell textInfo textShell read writeme));
  `I ("Checkout" , (fun () -> Depots.git (Depots.ask ()) "" "checkout" !_inShell textInfo textShell read writeme));
  `I ("Checkout-new" , (fun () -> Depots.git (Depots.ask ()) "" "checkout-new" !_inShell textInfo textShell read writeme));
  `I ("Checkout-redo" , (fun() -> Depots.git (Depots.ask ()) ""  "checkout-redo" !_inShell textInfo textShell read writeme));
  `I ("Checkout-rm" , (fun () -> Depots.git (Depots.ask ()) "" "checkout-rm" !_inShell textInfo textShell read writeme));
  `I ("Clone", (fun () -> Depots.git (Depots.ask ()) "" "clone" !_inShell textInfo textShell read writeme));
  `I ("Commit", (fun () -> Depots.git (Depots.ask ()) "" "commit" !_inShell textInfo textShell read writeme));
  `I ("Commit-file", (fun () -> Depots.git (Depots.ask ()) ""  "commit-file" !_inShell textInfo textShell read writeme));
  `I ("Diff", (fun () -> Depots.git (Depots.ask ()) (Depots.ask ()) "diff" !_inShell textInfo textShell read writeme));
  `I ("Fetch", (fun () -> Depots.git "" "" "fetch" !_inShell textInfo textShell read writeme)); 
  `I ("History", (fun () -> Depots.git "" "" "history" !_inShell textInfo textShell read writeme)); 
  `I ("Merge", (fun () -> Depots.git (Depots.ask ()) "" "merge" !_inShell textInfo textShell read writeme)); 
  `I ("Pull", (fun () -> Depots.git "" "" "pull" !_inShell textInfo textShell read writeme)); 
  `I ("Push" , (fun () -> Depots.git (Depots.ask ()) "" "push" !_inShell textInfo textShell read writeme));
  `I ("Remove", (fun () -> Depots.git (Depots.ask ()) "" "rm" !_inShell textInfo textShell read writeme));
  `I ("Tag", (fun () -> Depots.git (Depots.ask ()) (Depots.ask ()) "tag" !_inShell textInfo textShell read writeme));
]

let hgEntries = [
  `I ("Add", (fun () -> Depots.hg (Depots.ask ()) "add" !_inShell textInfo textShell read writeme));
  `I ("Branch", (fun () -> Depots.hg (Depots.ask ()) "branch" !_inShell textInfo textShell read writeme));
  `I ("Branches", (fun () -> Depots.hg "" "branches" !_inShell textInfo textShell read writeme));
  `I ("Clone", (fun () -> Depots.hg (Depots.ask ()) "clone" !_inShell textInfo textShell read writeme));
  `I ("Commit", (fun () -> Depots.hg (Depots.ask ()) "commit" !_inShell textInfo textShell read writeme));
  `I ("Commit-file", (fun () -> Depots.hg (Depots.ask ()) "commit-file" !_inShell textInfo textShell read writeme));
  `I ("Diff", (fun () -> Depots.hg "" "diff" !_inShell textInfo textShell read writeme));
  `I ("Diff-file", (fun () -> Depots.hg (Depots.ask ()) "diff-file" !_inShell textInfo textShell read writeme));
  `I ("Heads", (fun () -> Depots.hg "" "heads" !_inShell textInfo textShell read writeme)); 
  `I ("History", (fun () -> Depots.hg "" "history" !_inShell textInfo textShell read writeme)); 
  `I ("Incoming", (fun () -> Depots.hg "" "incoming" !_inShell textInfo textShell read writeme)); 
  `I ("Merge", (fun () -> Depots.hg (Depots.ask ()) "merge" !_inShell textInfo textShell read writeme)); 
  `I ("Pull", (fun () -> Depots.hg "" "pull" !_inShell textInfo textShell read writeme)); 
  `I ("Push" , (fun () -> Depots.hg "" "push" !_inShell textInfo textShell read writeme));
  `I ("Remove", (fun () -> Depots.hg (Depots.ask ()) "remove" !_inShell textInfo textShell read writeme));
  `I ("Status", (fun () -> Depots.hg "" "status" !_inShell textInfo textShell read writeme));
  `I ("Update", (fun () -> Depots.hg "" "update" !_inShell textInfo textShell read writeme));
  `I ("Update-redo", (fun () -> Depots.hg (Depots.ask ()) "update-redo" !_inShell textInfo textShell read writeme));
  `I ("Update-branch", (fun () -> Depots.hg (Depots.ask ()) "update-branch" !_inShell textInfo textShell read writeme));
]

let vcsEntries = [
  `C ("Operations in shell", false, toggleInShell);
  `S;
  `M ("SVN", svnEntries);
  `M ("Git", gitEntries);
  `M ("Mercurial", hgEntries);    
  `S;
  `I ("SVN Update", (fun () -> Depots.svn "" "" "update" !_inShell textInfo textShell read writeme));
  `I ("Git Checkout & Pull ", (fun () -> 
                                    Depots.git "" (Depots.ask()) "checkout" !_inShell textInfo textShell read writeme;
                                    Depots.git "" "" "pull" !_inShell textInfo textShell read writeme));
  `I ("Mercurial Update & Pull", (fun () -> 
                                    Depots.hg "" "update" !_inShell textInfo textShell read writeme;
                                    Depots.hg "" "pull" !_inShell textInfo textShell read writeme));
]

let toolEntries ()=
  [
    `I ("Fork real shell", (fun () -> Compil.fork_shell ()));
    `I ("Send to mini shell", 
            (fun () -> ask_minishell ()));
    `I ("Refresh mini shell", (fun () -> Compil.send_shell "\n" textShell read writeme; editShell#set_text ""));
    `S;
    `I ("Update `"^_sc_reload, reload);
  ]

let infoEntries ()=
  [
    `I ("Did you know the truth...", fun () -> print42());
    `S;
    `I ("About",aboutButton);
  ]
    
let optionList = GMenu.menu_item
  ~label:"File"
  ~packing:upMenu#append
  ()
  
let optionEdit = GMenu.menu_item
  ~label:"Edit"
  ~packing:upMenu#append
  ()
  
let optionVCS = GMenu.menu_item
  ~label:"VCS"
  ~packing:upMenu#append
  ()

let optionTool = GMenu.menu_item
  ~label:"Tools"
  ~packing:upMenu#append
  ()
  
let optionInfo = GMenu.menu_item
  ~label:"?"
  ~packing:upMenu#append
  ()
  
let menuOption = GMenu.menu ~packing:optionList#set_submenu ()
let menuEdit = GMenu.menu ~packing:optionEdit#set_submenu ()
let menuVCS  = GMenu.menu ~packing:optionVCS#set_submenu ()
let menuTool = GMenu.menu ~packing:optionTool#set_submenu ()
let menuInfo = GMenu.menu ~packing:optionInfo#set_submenu ()
  
let toolbox = GToolbox.build_menu
  menuOption
  ~entries:(fileEntries ())
  
  
let toolbox = GToolbox.build_menu
  menuEdit
  ~entries:(editEntries ())
  
let toolbox = GToolbox.build_menu
  menuVCS
  ~entries:(vcsEntries)

let toolbox = GToolbox.build_menu
  menuTool
  ~entries:(toolEntries ())
  
let toolbox = GToolbox.build_menu
  menuInfo
  ~entries:(infoEntries ())
  
  
(*** Button Open, About & Quit, Afficher un texte à l'écran ***)
      
let openButton = fileButton "Open" `OPEN load 

let saveButton = fileButton "Save" `SAVE save
      
let separator = 
  GMisc.separator `VERTICAL
    ~packing:toolBar#add ()
    
 
let compilButton = fileButton "Build" `MEDIA_PLAY compiler      

let separator2 = 
  GMisc.separator `VERTICAL
    ~packing:toolBar#add ()

(*** Intro ***)
let about_button = fileButton "About" `ABOUT aboutButton
let quitButton = fileButton "Quit" `QUIT (fun () -> ignore(quit ()); ())
     
let homeText =
  let text = open_in "text/presentation" in
  let length = in_channel_length text in
  let str = String.create length in
  let _ = really_input text str 0 length in
  let _ = close_in text in
  textCode#buffer#set_text (str)

let loadOpenedFiles = Settings.readSettings ();
if(!Settings.openedFiles <> []) then
begin
	List.iter (fun x -> ignore(createNewOnglet x); _filePath := x;
             Function.loadText !_filePath source_view noteBookCode textCode) !Settings.openedFiles
end 
(*** evenement clavier ***)

let _ = mainWindow#event#connect#any ~callback:(fun ev -> Compil.send_shell "" textShell read writeme; false)

let shortCut = let _ =
   mainWindow#event#connect#key_press ~callback:begin fun ev ->
   let m = GdkEvent.Key.state ev in
   let k = GdkEvent.Key.keyval ev in
   if (k = _F5) then compiler ();
   if (k = _F6) then reload ();
   if (k = _F7) then colorInfo ();
   if(List.mem `CONTROL m && k = _Return) then (Compil.send_shell (editShell#text) textShell read writeme; editShell#set_text "");
   if(List.mem `CONTROL m && k = _s) then save ();
   if(List.mem `CONTROL m && k = _o) then load ();
   if(List.mem `CONTROL m && k = _r) then ask_for_file ();
   if(List.mem `CONTROL m && k = _q) then ignore(quit ());();
   if(List.mem `CONTROL m && k = _t) then (ignore(createNewOnglet "Tab"));
   if(List.mem `CONTROL m && k = _w) then removeCurrentTab ();
    false
  end in
   editShell#event#connect#key_press ~callback:begin fun ev ->
   let k = GdkEvent.Key.keyval ev in
   if(k = _Return) then (Compil.send_shell (editShell#text) textShell read writeme; editShell#set_text "");
	 false
  end

let colorize () = let i = ref 0 in
    List.iter (fun txt -> noteBookCode#goto_page !i; i := !i + 1;
        txt#misc#modify_base [`NORMAL, `RGB (Settings.getBgColor ())];
        txt#misc#modify_text [`NORMAL, `RGB (Settings.getFgColor ())]) !Function._listText;
    textDebug#misc#modify_text [`NORMAL, `RGB (65535,65535,65535)];
    textDebug#misc#modify_base [`NORMAL, `RGB (0,0,0)];
    noteBookDebug#goto_page 1;
    textInfo#misc#modify_text [`NORMAL, `RGB (65535,65535,65535)];
    textInfo#misc#modify_base [`NORMAL, `RGB (0,0,0)];
    noteBookDebug#goto_page 0;
    textShell#misc#modify_text [`NORMAL, `RGB (65535,65535,65535)];
    textShell#misc#modify_base [`NORMAL, `RGB (0,0,0)];
    editShell#misc#modify_text [`NORMAL, `RGB (65535,65535,65535)];
    editShell#misc#modify_base [`NORMAL, `RGB (0,0,0)]
        

(*** Initialisation ***)
let _ =
  if Array.length Sys.argv > 1 then
    begin
      if Sys.argv.(1) = "--help" || Sys.argv.(1) = "-help" then 
	begin
	  let text = open_in "text/README" in
	  let length = in_channel_length text in
	  let str = String.create length in
	    really_input text str 0 length;
	    close_in text;
	    print_string str
	end
      else
	Printf.printf
	  ("\n\nWrite --help ou -help for more information\n\n")
    end
  else
    begin
      ignore(mainWindow#event#connect#delete quit);
      mainWindow#show ();
      mainWindow#maximize ();
      colorize ();
      GMain.main ()
    end

